<template>
  <div>
    <form action="">
        <!-- 搜索栏 -->
      <van-search
        v-model="value"
        show-action
        placeholder="请输入搜索关键词"
        @search="onSearch"
        @cancel="onCancel"
        is-link @click="showPopup"
      ></van-search>
    </form>

    <!-- 点击搜索栏弹出 -->
    <van-popup v-model="show" position="right" :style="{ height: '100%',width:'100%' }" >
      <SearchHistory></SearchHistory>
    </van-popup>

    
  </div>
</template>

<script>
import { Toast } from "vant"
import SearchHistory from "./SearchHistory"

export default {
  naem: "Search",
  data() {
    return {
      value: "",
      show: false,
    };
  },
  components: { SearchHistory },
  methods: {
    onSearch(val) {
        window.localStorage.setItem('history',val);
        Toast(val);
    },
    onCancel() {
      Toast("取消");
    },
    showPopup() {
        this.show = true;
    },
    exitPopup(){
        this.show=false;
    }
  },
  mounted() {
      this.$bus.$on('exitPopup',this.exitPopup);
  },
  beforeDestroy() {
      this.$bus.$off('exitPopup');
  },
  
};
</script>

<style>
</style>
